<%--
  Created by IntelliJ IDEA.
  User: 钻五大人
  Date: 2022/5/3
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" language="java" %>
<html>
<head>
    <title>RequestBody传递JSON类型的参数</title>
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./js/bootstrap.js"></script>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<body>
<button onclick="sendAjax();" class="btn btn-success">发送JSON数据到后端</button>

<script>
    function sendAjax(){
        let user = {id:1,username:"霏霏",password:"123",birthday:"1999-01-28",salary:12000.145,sex:""};
        let userDate = JSON.stringify(user);//将json对象转换为字符串
        // 使用ajax发送到json数据到后端控制器
        $.ajax({
            url:"http://localhost:8080${pageContext.request.contextPath}/ajax/test1",
            type:"post",
            contentType:"application/json",
            data:userDate,
            success:function (res){
                // alert(res);  前段调试的时候,在浏览器控制器输出信息
                console.log(res);
            }
        });
    }
</script>
</body>
</html>
